/**
 * 
 */
package com.manage.action;

import java.util.List;

import org.apache.log4j.Logger;


import com.action.AbstractAction;
import com.manage.cache.ChannelManager;
import com.manage.cache.ProjectManager;
import com.manage.model.Channel;
import com.manage.model.Project;

/**
 * @author jinmei.wang
 *
 */
public class ProjectAction extends AbstractAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Logger logger;
	
	public ProjectAction()
	{
		logger = Logger.getLogger(this.getClass());
	}
	
	public String execute()
	{
		return SUCCESS;
	}

	private List<Project> projects;
	private Project       project;
	private String        type;
	private Channel channel;
	
	public String list()
	{
		logger.debug("list account");
		channel = ChannelManager.getInstance().getChannel(channel.getId());
		projects = ProjectManager.getInstance().getProjects(channel.getId());
		return SUCCESS;
	}
	
	public String show()
	{
		if (project.getId() >= 0)
		{
			project = ProjectManager.getInstance().getProject(project.getId());
			type = "update";
		}
		else
		{
			project.setId(-1);
			type = "insert";
		}

		// channel = ChannelManager.getInstance().getChannel(project.getId());

		return SUCCESS;
	}
	
	public String shipDate;
	public String save()
	{
		project.setShipDate(shipDate);
		ProjectManager.getInstance().saveProject(operator, type, project);
		return SUCCESS;
	}

	/**
	 * @return the projects
	 */
	public List<Project> getProjects() {
		return projects;
	}

	/**
	 * @param projects the projects to set
	 */
	public void setProjects(List<Project> projects) {
		this.projects = projects;
	}

	/**
	 * @return the project
	 */
	public Project getProject() {
		return project;
	}

	/**
	 * @param project the project to set
	 */
	public void setProject(Project project) {
		this.project = project;
	}

	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * @return the channel
	 */
	public Channel getChannel() {
		return channel;
	}

	/**
	 * @param channel the channel to set
	 */
	public void setChannel(Channel channel) {
		this.channel = channel;
	}

	/**
	 * @return the shipDate
	 */
	public String getShipDate() {
		return shipDate;
	}

	/**
	 * @param shipDate the shipDate to set
	 */
	public void setShipDate(String shipDate) {
		this.shipDate = shipDate;
	}
}
